package servlets;
import dataManagers.*;
import entity.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class authenticationServlet extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");


        String username = request.getParameter("username");
        String password = request.getParameter("password");
        
        HttpSession session = request.getSession(true);
        RequestDispatcher dispatcher;
        
        
        if(username.equals("admin")){
            if(password.equals("password")){
                session.setAttribute("user","admin");
                response.sendRedirect("main.jsp");
            }
        }else{           
        String  errorMsg="Invalid username or password";
        request.setAttribute("errorMsg", errorMsg);
        dispatcher = request.getRequestDispatcher("index.jsp");
        dispatcher.forward(request, response);
    }

  }
}